package org.xg.study.pd;

import org.junit.Test;
import org.xg.study.pd.impl.InsideOrderService;
import org.xg.study.pd.impl.POPOrderAdapterServiceImpl;
import org.xg.study.pd.mq.CreateAccount;
import org.xg.study.pd.mq.OrderMQ;

import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * @author CMG
 * @version 1.0
 * @cLassName ApiTest6_02
 * @description
 * @date 2021/9/14 10:55
 **/
public class ApiTest6_02 {
    @Test
    public void test_mqAdapter() throws ParseException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss");
        Date date = s.parse("2021-09-14 23:23:23");
        CreateAccount createAccount = new CreateAccount();
        createAccount.setNumber("100001");
        createAccount.setAddress("河北省.廊坊市.广阳区.大学里职业技术学院");
        createAccount.setAccountDate(date);
        createAccount.setDesc("在校开户");

        HashMap<String ,String> link = new HashMap<>();
        link.put("userId","number");
        link.put("bizId","number");
        link.put("bizTime","accountDate");
        link.put("desc","desc");
        RebateInfo rebateInfo = MQAdapter.filter(createAccount.toString(), link);
        System.out.println("mq.CreateAccount(适配前)："+createAccount.toString());
        System.out.println("mq.CreateAccount(适配后)："+rebateInfo.toString());
        System.out.println("=============================================");


        OrderMQ orderMQ = new OrderMQ();
        orderMQ.setUid("100001");
        orderMQ.setSku("103221485648946313");
        orderMQ.setOrderId("102231455697520");
        orderMQ.setCreateOrderTime(date);

        HashMap<String,String> link1 = new HashMap<>();
        link1.put("userId","uid");
        link1.put("bizId","orderId");
        link1.put("bizTime","createOrderTime");
        RebateInfo rebateInfo1 = MQAdapter.filter(orderMQ.toString(),link1);
        System.out.println("mq.OrderMQ(适配前)："+orderMQ.toString());
        System.out.println("mq.OrderMQ(适配后)："+ rebateInfo1.toString());
        System.out.println("=============================================");
    }

    @Test
    public void test_itfAdapter(){
        OrderAdapterService adapterService = new POPOrderAdapterServiceImpl();
        System.out.println("判断首单，接口适配（POP）："+adapterService.isFirst("100001"));
        OrderAdapterService adapterService1 = new InsideOrderService();
        System.out.println("判断首单，接口适配（自营）："+ adapterService1.isFirst("100001"));
    }
}
